package com.wanxi.servlet.leave;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.VO.LeaveVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.LeaveService;
import com.wanxi.service.impl.LeaveServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : 林子淳
 * @create 2023/3/2 10:58
 */
//@WebServlet("/back/leave/findAll")
public class LeaveFinAllStrvlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.获取前端数据
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        //3.封装的VO内
        LeaveVO leaveVO = new LeaveVO();
        leaveVO.setPage(Tool.strToPage(page));
        leaveVO.setLimit(Tool.strToLimit(limit));
        //4.调用service
        LeaveService leaveService = new LeaveServiceImpl();
        //5.得到后台传回来的返回值
        ResultDTO resultDTO = leaveService.findAll(leaveVO);
        //6.把后端的返回值返回前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
